// 2025/11/6
// 买卖股票的最佳时机1

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int trough = prices[0], ans = 0, n = prices.size();
        for(int i = 1; i < n; i++)
        {
            if(prices[i] <= trough)
                trough = prices[i];
            else
                ans = max(ans, prices[i] - trough);
        }
        return ans;
    }
};